import React, { useEffect, useState } from "react";
import SelectHeader from '@c/selectHeader'
import AddPintuan from '@c/addPintuan'
import style from './style.module.css'
import { Table, Tag, Space, Switch, Button } from 'antd';
import { getPintuanData, delPintuanData, setPinTuanStart } from '@/api/request';
import { CloseOutlined, CheckOutlined } from '@ant-design/icons';
function GroupgoodsPage() {
  let [data, setData] = useState([])
  const changeData = (data) => {
    console.log(data)
    setData(data)
  }
  useEffect(async () => {
    let c = await getPintuanData()
    changeData(c.data.data)
  }, [])
  const clickstart = async (a, b) => {
    const res = await setPinTuanStart({ id: b.id, state: a });
    setData(res.data.data)
  }
  const columns = [
    {
      title: '商品ID',
      dataIndex: 'id',
      key: 'id',
    }, {
      title: '商品图片',
      dataIndex: 'image',
      key: 'image',
      render: aa => {
        return <img src={aa} alt="" />
      }
    }, {
      title: '商品标题',
      dataIndex: 'title',
      key: 'title',
    }, {
      title: '原价',
      dataIndex: 'peopleNum',
      key: 'peopleNum'
    }, {
      title: '拼团价',
      dataIndex: 'peopleNum',
      key: 'peopleNum',
      render: a => {
        return a / 2
      }
    }, {
      title: '结束时间',
      dataIndex: 'endTime',
      key: 'endTime',
    }, {
      title: '拼团状态',
      dataIndex: 'state',
      key: 'state',
      render: (a, b) => {
        return <Switch checkedChildren="开启" unCheckedChildren="关闭" defaultChecked={a} onChange={() => { clickstart(a, b) }} />
      }
    }, {
      title: '活动状态',
      dataIndex: 'state',
      key: 'state',
      render: a => {
        return a ? '进行中' : '已结束'
      }
    }, {
      title: '操作',
      dataIndex: 'id',
      key: 'id',
      render: (id) => {
        return <div>
          <Button onClick={() => { clickData(id) }}>  删除</Button>
        </div>
      }
    }
  ];
  const clickData = async (id) => {
    let c = await delPintuanData(id)
    changeData(c.data.data)
  }
  //添加按钮
  function addbth(data) {
    console.log(data)
    setData(data)
  }
  return <div className={style.GroupBigbox}>
    <SelectHeader clickaddbth={addbth}></SelectHeader>
    {/* {data} */}
    <div className={style.tableBox}>
      <Table columns={columns} rowKey='id' dataSource={data} />
    </div>
  </div>;
}
export default GroupgoodsPage;
